/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-27
 * Time: 15:28
 */
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}

class Message<T> {
    private T message;

    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Message<Fruit> message1 = new Message<>();
        message1.setMessage(new Fruit());
        fun2(message1);

        Message<Food> message2 = new Message<>();
        message2.setMessage(new Food());
        fun2(message2);
        Message<Apple> message3 = new Message<>();
        message3.setMessage(new Apple());
        //fun2(message3);//err
    }
    public static void fun2(Message<? super Fruit> tmp) {
        System.out.println(tmp.getMessage());
    }

    public static void main1(String[] args) {
        Message<Fruit> message1 = new Message<>();
        message1.setMessage(new Fruit());
        fun(message1);

        Message<Banana> message2 = new Message<>();
        message2.setMessage(new Banana());
        fun(message2);

        Message<Food> message3 = new Message<>();
        message3.setMessage(new Food());
        //fun(message3);//err
    }

    public static void fun(Message<? extends Fruit> tmp) {
        System.out.println(tmp.getMessage());
    }
}

